package com.ruoyi.project.wt.auditDaylogCreate.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.wt.auditDaylogQuery.domain.WtCheckDaylog;
import com.ruoyi.project.wt.auditDaylogQuery.domain.WtCheckDaylogQuery;
import com.ruoyi.project.wt.auditDaylogQuery.service.IWtCheckDaylogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.Arrays;
import java.util.List;

/**
 * 监督日志Controller
 *
 * @author 魏刚
 * @date 2020-03-18
 */
@Controller
@RequestMapping("/wt/auditDaylogCreate")
public class WtCheckDaylogCController extends BaseController
{
    private String prefix = "wt/auditDaylogCreate";

    @Autowired
    private IWtCheckDaylogService wtCheckDaylogService;

    @RequiresPermissions("wt:auditDaylogCreate:view")
    @GetMapping()
    public String auditDaylogCreate()
    {
        return prefix + "/auditDaylogCreateList";
    }

    /**
     * 查询监督日志列表
     */
    @RequiresPermissions("wt:auditDaylogCreate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WtCheckDaylogQuery wtCheckDaylogQuery)
    {
        startPage();
        List<WtCheckDaylog> list = wtCheckDaylogService.selectCreateList(wtCheckDaylogQuery);
        return getDataTable(list);
    }

    /**
     * 导出监督日志列表
     */
    @RequiresPermissions("wt:auditDaylogCreate:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WtCheckDaylogQuery wtCheckDaylog)
    {
        List<WtCheckDaylog> list = wtCheckDaylogService.selectCreateList(wtCheckDaylog);
        ExcelUtil<WtCheckDaylog> util = new ExcelUtil<WtCheckDaylog>(WtCheckDaylog.class);
        return util.exportExcel(list, "auditDaylogCreate");
    }
    /**
     * 下载监督日志
     */
    @RequiresPermissions("wt:auditDaylogCreate:downLoad")
    @PostMapping("/downLoad")
    @ResponseBody
    public AjaxResult downLoad(WtCheckDaylog wtCheckDaylog)
    {
        return wtCheckDaylogService.download(wtCheckDaylog);
    }
    /**
     * 新增监督日志
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        User user = ShiroUtils.getSysUser();
        mmap.put("user",user);
        return prefix + "/add";
    }

    /**
     * 新增保存监督日志
     */
    @RequiresPermissions("wt:auditDaylogCreate:addSave")
    @Log(title = "监督日志", businessType = BusinessType.INSERT)
    @PostMapping("/addSave")
    @ResponseBody
    public AjaxResult addSave(WtCheckDaylog wtCheckDaylog)
    {
        return toAjax(wtCheckDaylogService.addSave(wtCheckDaylog));
    }
    @RequiresPermissions("wt:auditDaylogCreate:addUpdate")
    @Log(title = "监督日志", businessType = BusinessType.UPDATE)
    @PostMapping("/addUpdate")
    @ResponseBody
    public AjaxResult addUpdate(WtCheckDaylog wtCheckDaylog)
    {
        return toAjax(wtCheckDaylogService.addUpdate(wtCheckDaylog));
    }
    /**
     * 删除监督日志
     */
    @RequiresPermissions("wt:auditDaylogCreate:remove")
    @Log(title = "监督日志", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wtCheckDaylogService.removeByIds(Arrays.asList(ids.split(","))));
    }
    /**
     * 查看监督日志
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = wtCheckDaylogService.getById(id);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        return prefix + "/checkDayLogView";
    }
    /**
     * 修改监督日志
     */
    @GetMapping("/modify/{id}")
    public String modify(@PathVariable("id") String id, ModelMap mmap)
    {
        WtCheckDaylog wtCheckDaylog = wtCheckDaylogService.getById(id);
        mmap.put("wtCheckDaylog", wtCheckDaylog);
        return prefix + "/edit";
    }
    /**
     * 审核监督日志
     */
    @RequiresPermissions("wt:auditDaylogCreate:auditing")
    @Log(title = "审核监督日志", businessType = BusinessType.UPDATE)
    @PostMapping("/auditing")
    @ResponseBody
    public AjaxResult auditing(WtCheckDaylog wtCheckDaylog)
    {
        return toAjax(wtCheckDaylogService.auditing(wtCheckDaylog));
    }
    /**
     * 退回监督日志
     */
    @RequiresPermissions("wt:auditDaylogCreate:auditingBack")
    @Log(title = "审核监督日志", businessType = BusinessType.UPDATE)
    @PostMapping("/auditingBack")
    @ResponseBody
    public AjaxResult auditingBack(WtCheckDaylog wtCheckDaylog)
    {
        return toAjax(wtCheckDaylogService.auditingBack(wtCheckDaylog));
    }
    /**
     * 退回监督日志
     */
    @RequiresPermissions("wt:auditDaylogCreate:doDateStatistics")
    @PostMapping("/doDateStatistics")
    @ResponseBody
    public AjaxResult doDateStatistics(WtCheckDaylogQuery wtCheckDaylog)
    {
        return AjaxResult.success(wtCheckDaylogService.doDateStatistics(wtCheckDaylog));
    }
}
